import java.util.Stack;

public class T {


    public static void main(String[] args) {
        MyQueue myQueue=new MyQueue();

        myQueue.push(1);
        myQueue.push(2);

        myQueue.peek();

    }
}

class MyQueue {


    Stack<Integer> stack1;
    Stack<Integer> stack2;


    public MyQueue() {

         stack1=new Stack<>();
         stack2=new Stack<>();

    }

    public void push(int x) {
        if(stack1.isEmpty()){
            stack2.push(x);
        }else {
            stack1.push(x);
        }

    }

    public int pop() {
        if(stack1.isEmpty()){
            int count=stack2.size()-1;

            for (int i = 0; i < count; i++) {
                stack1.push(stack2.pop());
            }

            int n=stack2.pop();

            for (int i = 0; i < count; i++) {
                stack2.push(stack1.pop());
            }
           return n;

        }

        return -1;


    }

    public int peek() {
        if(stack1.isEmpty()){
            int count=stack2.size()-1;

            for (int i = 0; i < count; i++) {
                stack1.push(stack2.pop());
            }

            int n=stack2.peek();

            for (int i = 0; i < count; i++) {
                stack2.push(stack1.pop());
            }
            return n;

        }

        return -1;



    }

    public boolean empty() {

        return stack1.empty()&&stack2.empty();

    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
